define(function() {
  var Record = Backbone.Model.extend({
    idAttribute: "_id",

    _data: [
      { name: 'name', type: 'string', value: '' },
      { name: 'title', type: 'string', value: '' },
      { name: 'text', type: 'text', value: '' },
      { name: 'image', type: 'string', value: '' },
      { name: 'completed', type: 'bool', value: false }
    ],

    defaults: function() {
      return _.reduce(this._data, function(res, d) { res[d.name] = d.value ; return res }, {})
    },

    getDataTypes: function() {
      return _.reduce(this._data, function(res, d) { res[d.name] = d.type ; return res }, {})
    },

    toFormData: function() {
      var defaults = this.defaults();
      if (this.isNew()) {
        return defaults;
      }
      else {
        return _.pick(_.extend({}, defaults, this.toJSON()), _.keys(defaults));
      }
    },

    toggle: function() {
    	this.save({ completed: !this.get('completed') });
    }
  });

  return Record;
});
